import sys
from PyQt5 import QtWidgets, QtCore
from widgets.excel import ExcelWidget
from widgets.search import SearchWidget


class LeftSideWidget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(LeftSideWidget, self).__init__(parent)
        self.parent = parent
        self.initUI()

    def initUI(self):
        self.vbox = QtWidgets.QVBoxLayout()
        self.excel = ExcelWidget(self)
        self.vbox.addWidget(self.excel)
        self.setLayout(self.vbox)


class RightSideWidget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(RightSideWidget, self).__init__(parent)
        self.parent = parent
        self.initUI()

    def initUI(self):
        self.vbox = QtWidgets.QVBoxLayout()
        self.gen_btn = QtWidgets.QPushButton("生成截图", self)
        self.clr_btn = QtWidgets.QPushButton("清理截图", self)
        self.vbox.addWidget(self.gen_btn)
        self.vbox.addWidget(self.clr_btn)
        self.space = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.vbox.addSpacerItem(self.space)
        self.setLayout(self.vbox)


        self.gen_btn.clicked.connect(self.generate_snapshot)
        self.clr_btn.clicked.connect(self.clear_snapshot)

    def generate_snapshot(self):
        print("成功截图中...")

    def clear_snapshot(self):
        print("清理截图成功...")


class MyWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(MyWindow, self).__init__()
        self.initUI()

    def initUI(self):
        self.resize(1024, 768)
        menubar = self.menuBar()
        menubar.addAction("上传Excel", self.select_excel)
        menubar.addAction("导出Excel", self.export_excel)
        menubar.addAction("系统设置", self.setup)
        self.search = SearchWidget(self)
        menubar.setCornerWidget(self.search, QtCore.Qt.TopRightCorner)
        self.container = QtWidgets.QWidget(self)
        self.hbox = QtWidgets.QHBoxLayout()
        self.leftside = LeftSideWidget(self)
        self.rightside = RightSideWidget(self)
        self.hbox.addWidget(self.leftside)
        self.hbox.addWidget(self.rightside)
        self.container.setLayout(self.hbox)
        self.setCentralWidget(self.container)

    def select_excel(self):
        pass

    def export_excel(self):
        pass

    def setup(self):
        pass

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    mw = MyWindow()
    mw.show()
    sys.exit(app.exec_())